Imports WindowsLive.Writer.Api
Imports System.Windows.Forms

<WriterPluginAttribute("d7bf807d-7bb0-458a-811f-90c51817d5c2", _
"Insert Tags", _
Description:="Inserts tags (e.g. Technorati) and links into your post.", _
HasEditableOptions:=True, _
ImagePath:="Tags.png", _
PublisherUrl:="http://tech.pederborgpoulsen.dk/windows-live-writer-plugins"), _
InsertableContentSourceAttribute("Tags")> _
Public Class InsertSmartTags

    'Inheritance
    Inherits SmartContentSource

    Public Shared myTags As String = String.Empty
    Public Shared arSites As ArrayList

    Public Shared mySitesTags As IProperties

    'Overrides the function CreateContent
    Public Overrides Function CreateContent(ByVal dialogOwner As System.Windows.Forms.IWin32Window, ByVal newContent As WindowsLive.Writer.Api.ISmartContent) As System.Windows.Forms.DialogResult

        'mySitesTags.SetString("peder", "test")
        'Creating a new object of the FormTags
        Using InsertForm As FormTags = New FormTags

            'Creating a dialogresult that holds the result of the FormTags
            Dim Result As DialogResult = InsertForm.ShowDialog
            Dim Create As CreateTags = New CreateTags

            Try

                'Getting the HTML for tags
                If (Result = DialogResult.OK) Then
                    myTags = InsertForm.txtTags.Text
                    newContent.Properties.SetString("TAGS", Create.CreateTags(myTags))
                End If

                'Returns to caller
                Return Result

            Catch ex As Exception

                Dim mylog As New LogFile
                mylog.WriteToLog(ex.Message.ToString & " " & ex.InnerException.ToString)

            End Try

        End Using


    End Function

    Public Overrides Sub EditOptions(ByVal dialogOwner As System.Windows.Forms.IWin32Window)

        Using myFormOptions As FormTagsOptions = New FormTagsOptions

            Try
                myFormOptions.ShowDialog()
            Catch ex As Exception

            End Try


        End Using
    End Sub

    Public Overrides Function CreateEditor(ByVal editorSite As WindowsLive.Writer.Api.ISmartContentEditorSite) As WindowsLive.Writer.Api.SmartContentEditor
        Dim myEditor As TagsEditor = New TagsEditor(editorSite)
        Return myEditor
    End Function

    Public Overrides Function GeneratePublishHtml(ByVal content As WindowsLive.Writer.Api.ISmartContent, ByVal publishingContext As WindowsLive.Writer.Api.IPublishingContext) As String
        Try
            Dim myContent As String = content.Properties.GetString("TAGS", String.Empty)
            Return myContent.ToString
        Catch ex As Exception
            Throw New Exception(ex.Message, ex.InnerException)
            Return String.Empty
        End Try


    End Function

    Public Overrides ReadOnly Property ResizeCapabilities() As WindowsLive.Writer.Api.ResizeCapabilities
        Get
            Return WindowsLive.Writer.Api.ResizeCapabilities.Resizable
        End Get
    End Property

    Public Overrides Sub OnResizeComplete(ByVal content As WindowsLive.Writer.Api.ISmartContent, ByVal newSize As System.Drawing.Size)
        MyBase.OnResizeComplete(content, newSize)
        content.Properties.SetString("Height", newSize.Height.ToString)
        content.Properties.SetString("Width", newSize.Width.ToString)
    End Sub

End Class

